<?php
require_once('content.php');
require_once('../tags/tags.php');
require_once('../auth.php');

if (!isUserLoggedIn()) {
	header("Location: index.php");
	exit();
}

if (!isset($_POST['packageName']) && !isset($_POST["fileName"]) && !isset($_POST["tags"])) {
	echo "Error!";
	exit();
}

$content = new Content();

// Save tags
$tags = json_decode($_POST["tags"]);
if ($tags) {
	$tagsObj = new Tags();
	$tagsObj->saveTags($tags);
}

$corpus = $_POST["corpus"];

$content->addContent($_POST['packageName'], $_POST['fileName'], $tags, $corpus);

?>